package com.medistat.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.hibernate.annotations.GenericGenerator;

@Entity
public class Schedule extends StandardPersistentObject {
	
	@Id @GeneratedValue(generator="ID_GENERATOR_FOR_SCHEDULE")
	@GenericGenerator(name="ID_GENERATOR_FOR_SCHEDULE", strategy = "increment")
	private Long id;
	
	private Integer week;
	private Integer year;
	
	//parent reference
	@ManyToOne(targetEntity=Department.class)	
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})	
	@JoinColumns({ @JoinColumn(name="DepartmentID", referencedColumnName="ID") })	
	@Basic(fetch=FetchType.LAZY)
	private Department department;
	
	//dependent work
	@OneToMany(mappedBy="schedule", targetEntity=Work.class)	
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.FALSE)	
	private List<Work> listOfWorks = new ArrayList<Work>();

	public Long getId() {
		return id;
	}
	
	public Integer getWeek() {
		return week;
	}

	public void setWeek(Integer week) {
		this.week = week;
	}

	public Integer getYear() {
		return year;
	}

	public void setYear(Integer year) {
		this.year = year;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public List<Work> getListOfWorks() {
		return listOfWorks;
	}

	public void setListOfWorks(List<Work> daysInWeek) {
		this.listOfWorks = daysInWeek;
	}
	
	public void addToListOfWork(Work work) throws Exception {
		addDependentToParent(work, Schedule.class);
	}
}
